package com.caifu.controller;


import com.caifu.bean.Result;
import com.caifu.pojo.SysUser;
import com.caifu.service.CUserRecordService;
import com.caifu.util.Utils;
import com.caifu.vo.RecordVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 * 人员进出记录表 前端控制器
 * </p>
 *
 * @author tww
 * @since 2020-12-14
 */
@Controller
@RequestMapping("record")
public class CUserRecordController extends AbstractController {

    final static Logger logger = LoggerFactory.getLogger(CUserRecordController.class);

    @Resource
    private CUserRecordService cUserRecordService;

    /**
     * 跳进入记录页
     */
    @GetMapping("toRecordPage")
    public String toRecordPage() {
        return "view/record/user_record";
    }

    /**
     * 获取记录列表 分页
     */
    @GetMapping("getRecordList")
    @ResponseBody
    public Result getRecordList(RecordVo recordVo) {
        SysUser user = getUser();
        try {
            return success(0, "", cUserRecordService.getRecordList(recordVo,user));
        } catch (Exception e) {
            String msg = "网络异常";
            if (Utils.isNotNull(e.getMessage())) {
                msg = e.getMessage();
            }
            logger.error(e.toString());
            e.printStackTrace();
            return error(500, msg);
        }
    }


}
